const regeneratorRuntime = require('../../../utils/runtime.js')
const $ = require('../../../utils/util.js')
const app = getApp()


Page({
  data: {
    parent_id: 650000, // 获取设备树【省市区】 0,1,2,3 ...
    treeList: [], // 树列表
  },  
  onLoad: function (options) {
    this.setData({
      parent_id: options.parent_id || 650000
    })

    this._tree(this.data.parent_id).then(({ data }) => {
      this.setData({
        treeList: data
      })
    })
 
  },
  onShow: function () {

  },
  _tree(parent_id){ // 获取树
    return new Promise((resolve, reject)=>{
      app.$http.post('/lock/tree', { parent_id }).then(res => {
        if (res && res.code == 0) resolve(res)
      })
    })
  },
  async toNextHandle(e){ // 去下个页面
    let { item: { dept_id, dept_name, parent_id} } = $.detail(e)
    let _res = await this._tree(dept_id)
    if(_res.data.length>0){
      $.linkurl(`/pages/lockMange/chooseSsq/chooseSsq?parent_id=${dept_id}`)
    } else {
      $.linkurl(`/pages/lockMange/chooseSsqLast/chooseSsqLast?dept_id=${dept_id}`)  
    }
 
  }
})